package bookstore.service;

import bookstore.handle.Msg;
import bookstore.mapper.BookMapper;
import bookstore.model.Book;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    BookMapper bookMapper;
    //按照页码查询书籍
    public Object bookList(Integer page){
        if(page<=0){
            return new Msg(0,"请传入正确的页码");
        }
        IPage<Book> list=bookMapper.selectPage(new Page<Book>(page, 100),null);
        return new Msg(200,"",list);
    }
    //按照like来进行搜索
    public Object bookByName(String name){
        List<Book> list=bookMapper.selectList(new QueryWrapper<Book>().like("title",name));
        return new Msg(200,"",list);
    }
}
